package network;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

public class UDPTranServer extends UDPServer {
    HashMap<String, String> hashMap = new HashMap<>();

    public UDPTranServer(int port) throws SocketException {
        super(port);
        hashMap.put("cat", "猫");//注意在实例化后就能进行查找
        hashMap.put("dog", "狗");
        hashMap.put("fish", "鱼");
        hashMap.put("pig", "猪");
    }

    @Override
    public String process(String request) {

        // 参数是一个英文单词.
        // 返回值是一个对应的汉语.
        return hashMap.getOrDefault(request, "您查的单词不存在!");
    }


    public static void main(String[] args) throws IOException {
        UDPTranServer server = new UDPTranServer(9090);
        server.start();
    }

}
